/**
 * 
 */
package com.ph.shopping.common.core.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * @项目：phshopping-common-core
 *
 * @描述：实体base类
 *
 * @作者： Mr.chang
 *
 * @创建时间：2017年3月8日
 *
 * @Copyright @2017 by Mr.chang
 */
public class BaseEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5300113985007593228L;
	
	@Column(name="createTime")
	private Date createTime;
	
	@Id
	private Long id;

	@Column(name="updateTime")
	private Date updateTime;

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}
	
	public Long getId() {
		return id;
	}

	/**
	 * @return the updateTime
	 */
	public Date getUpdateTime() {
		return updateTime;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param updateTime the updateTime to set
	 */
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}


	//验证FormBean
	  public  List<String> validateForm(){
		  List<String> errorList = null; 
		  ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
		   Validator validator  = factory.getValidator();
	       Set<ConstraintViolation<BaseEntity>> constraintViolation = validator.validate(this); 
	       if(constraintViolation.size() > 0)
	    	    errorList = new ArrayList<String>(constraintViolation.size());
	       for(ConstraintViolation<BaseEntity> violation : constraintViolation){
	    	   errorList.add(violation.getMessage());
	       }
	        return errorList;
	  }
	
}
